import type { RouteRecordRaw } from 'vue-router'
import Layout from '@/layout/index.vue'
import Home from '@/views/home/index.vue'
import Design from '@/views/process/Design.vue'
import ProcessList from '@/views/process/List.vue'
import ProcessTask from '@/views/process/Task.vue'
import ProductList from '@/views/product/List.vue'
import ProductTag from '@/views/product/Tag.vue'
import ProductType from '@/views/product/Type.vue'
import SystemLog from '@/views/system/Log.vue'
import SystemOrganization from '@/views/system/Organization.vue'
import SystemPermission from '@/views/system/Permission.vue'
import SystemRole from '@/views/system/Role.vue'
import SystemUser from '@/views/system/User.vue'

// 定义路由配置
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Home',
        component: Home,
        meta: {
          title: '首页',
          requiresAuth: true,
        },
      },
      {
        path: 'product',
        name: 'Product',
        redirect: '/product/list',
        meta: {
          title: '产品管理',
        },
        children: [
          {
            path: 'list',
            name: 'ProductList',
            component: ProductList,
            meta: {
              title: '产品列表',
              requiresAuth: true,
            },
          },
          {
            path: 'tag',
            name: 'ProductTag',
            component: ProductTag,
            meta: {
              title: '标签列表',
              requiresAuth: true,
            },
          },
          {
            path: 'type',
            name: 'ProductType',
            component: ProductType,
            meta: {
              title: '类型列表',
              requiresAuth: true,
            },
          },
        ],
      },
      {
        path: 'process',
        name: 'Process',
        redirect: '/process/task',
        meta: {
          title: '流程管理',
        },
        children: [
          {
            path: 'task',
            name: 'ProcessTask',
            component: ProcessTask,
            meta: {
              title: '任务列表',
              requiresAuth: true,
            },
          },
          {
            path: 'list',
            name: 'ProcessList',
            component: ProcessList,
            meta: {
              title: '流程列表',
              requiresAuth: true,
            },
          },
          {
            path: 'design',
            name: 'Design',
            component: Design,
            meta: {
              title: '流程创建',
              requiresAuth: true,
            },
          },
        ],
      },
      {
        path: 'system',
        name: 'System',
        redirect: '/system/user',
        meta: {
          title: '系统管理',
        },
        children: [
          {
            path: 'user',
            name: 'SystemUser',
            component: SystemUser,
            meta: {
              title: '用户管理',
              requiresAuth: true,
            },
          },
          {
            path: 'organization',
            name: 'SystemOrganization',
            component: SystemOrganization,
            meta: {
              title: '组织管理',
              requiresAuth: true,
            },
          },
          {
            path: 'role',
            name: 'SystemRole',
            component: SystemRole,
            meta: {
              title: '角色管理',
              requiresAuth: true,
            },
          },
          {
            path: 'permission',
            name: 'SystemPermission',
            component: SystemPermission,
            meta: {
              title: '权限管理',
              requiresAuth: true,
            },
          },
          {
            path: 'log',
            name: 'SystemLog',
            component: SystemLog,
            meta: {
              title: '日志审计',
              requiresAuth: true,
            },
          },
        ],
      },
    ],
  },
  {
    path: '/:pathMatch(.*)*', // 404 页面
    name: 'NotFound',
    component: () => import('@/views/404/index.vue'),
    meta: {
      title: '页面未找到',
    },
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录',
    },
  },
]

export default routes
